package com.yztc.orangeentertainment.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.base.OnItemClickListener;
import com.yztc.orangeentertainment.bean.channalbean.ChannalTitleDataBean;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/9.
 */
public class ChannalPopupWindowAdapter extends RecyclerView.Adapter<ChannalPopupWindowAdapter.MyViewHolder> {
    private Context context;
    private List<ChannalTitleDataBean> titleDataBeanListBean;
    private OnItemClickListener itemClickListener;

    public void setItemClickListener(OnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    public ChannalPopupWindowAdapter(Context context, List<ChannalTitleDataBean> titleDataBeanListBean) {
        this.context = context;
        this.titleDataBeanListBean = titleDataBeanListBean;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.channalpopupwindow_item, parent,
                false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        holder.sdChannalpopwinitem.setImageURI(titleDataBeanListBean.get(position).getPic());
        holder.tvChannalpopwintitleitem.setText(titleDataBeanListBean.get(position).getName());
        if (itemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    itemClickListener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    itemClickListener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return titleDataBeanListBean.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.sd_channalpopwinitem)
        SimpleDraweeView sdChannalpopwinitem;
        @InjectView(R.id.tv_channalpopwintitleitem)
        TextView tvChannalpopwintitleitem;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }
}
